<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="文件类型" prop="filetype">
        <el-select v-model="queryParams.filetype" placeholder="请选择文件类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>

      <el-form-item label="办理起止时间" label-width="100px">
        <el-date-picker v-model="daterangeFinishtime" size="small" style="width: 240px" value-format="yyyy-MM-dd"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="文件标题" prop="subject">
        <el-input v-model="queryParams.subject" placeholder="请输入文件标题" clearable size="small"  style="width:500px;"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="mydoneList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="文件类型" align="center" prop="filetype" width="200" />
      <el-table-column label="处理环节" align="center" prop="taskname" width="200" />
      <el-table-column label="处理时间" align="center" prop="finishtime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.finishtime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="文件标题" align="center" prop="subject" />
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
  import {
    listMydone,
    getMydone,
    exportMydone
  } from "@/api/oa/mydone";

  export default {
    name: "Mydone",
    components: {},
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // VIEW表格数据
        mydoneList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 流程实例ID时间范围
        daterangeFinishtime: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          filetype: null,
          taskname: null,
          finishtime: null,
          currentuser: null,
          instanceid: null,
          subject: null,
          docunid: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询VIEW列表 */
      getList() {
        this.loading = true;
        this.queryParams.params = {};
        this.queryParams.currentuser=this.$store.getters.name;
        if (null != this.daterangeFinishtime && '' != this.daterangeFinishtime) {
          this.queryParams.params["beginFinishtime"] = this.daterangeFinishtime[0];
          this.queryParams.params["endFinishtime"] = this.daterangeFinishtime[1];
        }
        listMydone(this.queryParams).then(response => {
          this.mydoneList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.daterangeFinishtime = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.filetype)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有VIEW数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportMydone(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
      }
    }
  };
</script>
